//
//  InputDetailViewController.m
//  OperationPro
//
//  Created by yaxue wang on 2017/1/3.
//  Copyright © 2017年 展鸿科技. All rights reserved.
//

#import "InputDetailViewController.h"
#import "SDImageCache.h"
#import "UIImageView+WebCache.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>
#import "TZImageManager.h"
#import "TZImagePickerController.h"
#import "MWPhotoBrowser.h"
#import "VoiceConverter.h"
#import "LocationViewController.h"
#import "HistoryViewController.h"
@interface InputDetailViewController ()<MWPhotoBrowserDelegate>
{
    TPKeyboardAvoidingScrollView *_scrollView;
    NSString *_urlString;
    NSMutableArray *_photosAr;
    NSMutableArray *_videoAr;
    UIImageView *_imageView;
    UILabel *_timeLab;
    NSInteger _soundClick;
    
    
}
@property(nonatomic,strong)AVAudioPlayer *audioPlayer;
@end

@implementation InputDetailViewController

- (void)initView {
    [super initView];
    [self setTitle:@"报修单详情"];
    NSInteger num =[self.state integerValue];
    if (num==0||num==1||num==2) {
        [self.navBar createRightBtn:@"取消" block:^{
            [CClass HttpRequestTask:YES withUrl:@"warning_orderCancel" withData:@{@"orderUuid":self.Uuid} notifyError:YES onSuccess:^(BaseModel *model) {
                [CClass showLittleTimeMessage:@"取消报修成功"  completion:^{
                    [self.navigationController popToRootViewControllerAnimated:YES];
                    
                }];
            } onError:^(BaseModel *model) {
                
            }];
        }];
    }

    
    _soundClick=0;
    _scrollView=[[TPKeyboardAvoidingScrollView alloc]initWithFrame:CGRectMake(0, 64, WindowWidth, WindowHeight-64)];
    _scrollView.backgroundColor=BackColor;
    [self.view addSubview:_scrollView];
    //详情请求
    NSString *warn =self.Uuid;
    [CClass HttpRequestTask:YES withUrl:@"warninglist_orderContent" withData:@{@"warningUuid":warn} notifyError:YES onSuccess:^(BaseModel *model) {
        NSDictionary *dataDic=model.B_data;
        [self showDataDict:dataDic];
    } onError:^(BaseModel *model) {
        
    }];
    
    _photosAr = [NSMutableArray array];
}
-(void)showDataDict:(NSDictionary *)dict
{
    _urlString =[CClass getCacheData:qnDomain];
    UIView*topView=[[UIView alloc]initWithFrame:CGRectMake(0, 10, WindowWidth, 10)];
    topView.backgroundColor=[UIColor whiteColor];
    [_scrollView addSubview:topView];
#pragma mark设备
    NSString *machineName;
    NSString *typeNm;
    
    UILabel*equipmentLab=[[UILabel alloc]init];
    [topView addSubview:equipmentLab];
    equipmentLab.text =@"报修设备";
    equipmentLab.textColor =FontColor;
    equipmentLab.font =FF(14);
    UILabel*nameLab=[[UILabel alloc]init];
    [topView addSubview:nameLab];
    
    nameLab.text =[NSString stringWithFormat:@"%@\n%@",typeNm,machineName];
    nameLab.textColor =MainColor;
    nameLab.font =FF(14);
    nameLab.numberOfLines=0;
    nameLab.userInteractionEnabled=YES;
    
    
    if([F_NSpace([dict objectForKey:@"machineName"]) isEqualToString:@""]&&[F_NSpace([dict objectForKey:@"typeNm"]) isEqualToString:@""]){
        
        equipmentLab.frame=CGRectMake(25, 15, 65, 15);
        nameLab.frame=CGRectMake(CGRectGetMaxX(equipmentLab.frame), 15, WindowWidth-CGRectGetMaxX(equipmentLab.frame), 15);
        nameLab.text=@"未添加";
        nameLab.textColor =FontColor;
        
        
    }else
    {
        
        if ([F_NSpace([dict objectForKey:@"machineName"]) isEqualToString:@""]) {
            typeNm=[dict objectForKey:@"typeNm"];
            CGSize typeNmsize = [typeNm sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-65, 900)];
            equipmentLab.frame=CGRectMake(25, 15, 65, 15);
            nameLab.frame=CGRectMake(CGRectGetMaxX(equipmentLab.frame), 15, WindowWidth-CGRectGetMaxX(equipmentLab.frame), typeNmsize.height);
            nameLab.text =[NSString stringWithFormat:@"%@",typeNm];
            [nameLab bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                HistoryViewController *historyVC =[[HistoryViewController alloc]init];
                historyVC.machineUuid =[dict objectForKey:@"machine_uuid"];
                historyVC.Type=MachineLink;//已经关联
                historyVC.orderUuid=@"";
                //没有取消关联功能
                historyVC.num=1000;
                [self pushController:historyVC];
            }];
            
        }else if ([F_NSpace([dict objectForKey:@"typeNm"]) isEqualToString:@""])
        {
            machineName=[dict objectForKey:@"machineName"];
            
            CGSize namesize = [machineName sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-65, 900)];
            equipmentLab.frame=CGRectMake(25, 15, 65, 15);
            nameLab.frame=CGRectMake(CGRectGetMaxX(equipmentLab.frame), 15, WindowWidth-CGRectGetMaxX(equipmentLab.frame), namesize.height);
            nameLab.text =[NSString stringWithFormat:@"%@",machineName];
            [nameLab bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                HistoryViewController *historyVC =[[HistoryViewController alloc]init];
                historyVC.machineUuid =[dict objectForKey:@"machine_uuid"];
                historyVC.orderUuid=@"";
                //没有取消关联功能
                historyVC.num=1000;
                historyVC.Type=MachineLink;//已经关联
                [self pushController:historyVC];
                
            }];
        }else
        {
            machineName=[dict objectForKey:@"machineName"];
            typeNm=[dict objectForKey:@"typeNm"];
            
            CGSize namesize = [machineName sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-65, 900)];
            CGSize typesize = [typeNm sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-65, 900)];
            equipmentLab.frame=CGRectMake(25, 15, 65, 15);
            nameLab.frame=CGRectMake(CGRectGetMaxX(equipmentLab.frame), 15, WindowWidth-CGRectGetMaxX(equipmentLab.frame), namesize.height+typesize.height);
            nameLab.text =[NSString stringWithFormat:@"%@\n%@",typeNm,machineName];
            [nameLab bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                HistoryViewController *historyVC =[[HistoryViewController alloc]init];
                historyVC.machineUuid =[dict objectForKey:@"machine_uuid"];
                historyVC.orderUuid=@"";
                //没有取消关联功能
                historyVC.num=1000;
                historyVC.Type=MachineLink;//已经关联
                [self pushController:historyVC];
                
            }];
            
        }
    }
    
    CGSize size ;
    if ([F_NSpace([dict objectForKey:@"describe"]) isEqualToString:@""]) {
        size.height=0;
    }else
    {
        
        size = [[dict objectForKey:@"describe"] sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-50, 900)];
    }
    
    UILabel*lab2=[[UILabel alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(nameLab.frame)+15, 65, 15)];
    [topView addSubview:lab2];
    lab2.text =@"报修内容";
    lab2.textColor =FontColor;
    lab2.font= FF(14);
    
    UILabel*lab3=[[UILabel alloc]initWithFrame:CGRectMake(25,CGRectGetMaxY(lab2.frame)+5, WindowWidth-50,size.height)];
    [topView addSubview:lab3];
    if ([F_NSpace([dict objectForKey:@"describe"]) isEqualToString:@""]) {
        
        lab3.text =@"";
    }else
    {
        lab3.text =[dict objectForKey:@"describe"];
        
    }
    lab3.textColor =LightFontColor;
    lab3.font= F(11);
    lab3.numberOfLines=0;
    
    CGFloat imgorighY;
    if([F_NSpace([dict objectForKey:@"audioAmr"]) isEqualToString:@""])
    {
        imgorighY=CGRectGetMaxY(lab3.frame);
        
    }else
    {
        
        NSString *translator = [NSString stringWithFormat:@"(%@)",[dict objectForKey:@"audio_translator"]];
        
        CGSize  tranSize = [translator sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-50, 900)];
        imgorighY=CGRectGetMaxY(lab3.frame)+40+tranSize.height+10;
        //语音
        //1.音频文件的url路径
        NSURL *voiceUrl =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",_urlString,[dict objectForKey:@"audioAmr"]]];
        NSData * audioData = [NSData dataWithContentsOfURL:voiceUrl];
        
        //将数据保存到本地指定位置
        NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *filePath = [NSString stringWithFormat:@"%@/%@.amr", docDirPath , @"temp"];
        [audioData writeToFile:filePath atomically:YES];
        
        
        NSFileManager *fileManager = [NSFileManager defaultManager];
        if([fileManager removeItemAtPath:filePath error:nil])
        {
            echo(@"删除以前的arm文件");
        }else
        {
            [audioData writeToFile:filePath atomically:YES];
            
        }
        //转码之后的WAV文件
        NSString *playPath = [NSString stringWithFormat:@"%@/%@.wav", docDirPath , @"play"];
        if([fileManager removeItemAtPath:filePath error:nil])
        {
            echo(@"删除以前的wav文件");
        }else
        {
            [audioData writeToFile:filePath atomically:YES];
            
        }
        
        [VoiceConverter ConvertAmrToWav:filePath wavSavePath:playPath];
        
        
        //播放录音
        NSError *error;
        AVAudioSession *seesion= [AVAudioSession sharedInstance];
        //混音播放
        [seesion setCategory:AVAudioSessionCategoryPlayback error:nil];
        [seesion setActive:YES error:nil];
        
        //播放本地音乐
        NSURL *fileURL = [NSURL fileURLWithPath:playPath];
        self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
        
        UIButton *soudBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        soudBtn.frame =CGRectMake(25, CGRectGetMaxY(lab3.frame), 200, 30);
        [soudBtn setBackgroundImage:[UIImage imageNamed:@"Ico_home_ soundBg"] forState:UIControlStateNormal];
        [soudBtn setBackgroundImage:[UIImage imageNamed:@"Ico_home_ soundBg"] forState:UIControlStateSelected];
        
        [topView addSubview:soudBtn];
        
        _timeLab =[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(soudBtn.frame)+5,CGRectGetMaxY(lab3.frame), topView.bounds.size.width-CGRectGetMaxX(soudBtn.frame)-20, 30)];
        _timeLab.font =FF(12);
        _timeLab.hidden=NO;
        _timeLab.text =[NSString stringWithFormat:@"%ld s",(long)self.audioPlayer .duration];
        [topView addSubview:_timeLab];
        _timeLab.textColor =C(@"909090");
        
        //定义数组，存放所有图片对象
        NSArray *images=[NSArray arrayWithObjects:[UIImage imageNamed:@"Ico_home_ sonic1"],[UIImage imageNamed:@"Ico_home_ sonic2"],[UIImage imageNamed:@"Ico_home_ sonic3"],nil];
        _imageView =[[UIImageView alloc]initWithFrame:CGRectMake(10, 1, 35, 28)];
        _imageView.image =[UIImage imageNamed:@"Ico_home_ sonic3"];
        //imageView的动画图片是数组images
        _imageView.animationImages = images;
        //按照原始比例缩放图片，保持纵横比
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        //切换动作的时间3秒，来控制图像显示的速度有多快，
        _imageView.animationDuration = 3;
        //动画的重复次数，想让它无限循环就赋成0
        _imageView.animationRepeatCount = 0;
        //添加控件
        [soudBtn addSubview:_imageView];
        
        [soudBtn bk_addEventHandler:^(id sender) {
            
            _soundClick++;
            if (_soundClick%2==0) {
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                
            }else{
                if (self.audioPlayer  == nil)
                {
                    echo(([NSString stringWithFormat:@"ERror creating player: %@", [error description]]));
                }else{
                    //准备播放
                    [self.audioPlayer  prepareToPlay];
                    //播放
                    [self.audioPlayer  play];
                    
                    //开始动画
                    [_imageView startAnimating];
                    
                    __block  NSInteger duration = (NSInteger)self.audioPlayer .duration;
                    NSTimeInterval period = 1.0; //设置时间间隔
                    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
                    dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), period * NSEC_PER_SEC, 0); //每秒执行
                    dispatch_source_set_event_handler(_timer, ^{
                        dispatch_async(dispatch_get_main_queue(), ^{
                            
                        });
                        if (duration -- <= 0 ) {
                            dispatch_source_cancel(_timer);
                            dispatch_async(dispatch_get_main_queue(), ^{
                                _soundClick+=1;
                                //关闭动画
                                [_imageView stopAnimating];
                            });
                        }
                    });
                    dispatch_resume(_timer);
                    
                }
                
            }
            
        } forControlEvents:UIControlEventTouchUpInside];
        UILabel *transLab=[[UILabel alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(soudBtn.frame)+5, WindowWidth-50, tranSize.height)];
        transLab.textColor =LightFontColor;
        transLab.font= FF(11);
        transLab.numberOfLines=0;
        transLab.text=translator;
        [topView addSubview:transLab];
        
    }
    CGFloat width =(WindowWidth-30-50)/3;
    
    CGFloat imgHeight;
    
    if ([F_NSpace([dict objectForKey:@"image"]) isEqualToString:@""]&&[F_NSpace([dict objectForKey:@"video"]) isEqualToString:@""]) {
        
        
        
    }else if( [F_NSpace([dict objectForKey:@"image"]) isEqualToString:@""]||[F_NSpace([dict objectForKey:@"video"]) isEqualToString:@""]){
        if ([F_NSpace([dict objectForKey:@"video"]) isEqualToString:@""]) {
            //只有图片
            NSString *str =[dict objectForKey:@"image"];
            imgHeight=width+10;
            
            NSArray *array = [str componentsSeparatedByString:@","];
            for (int i=0; i<array.count; i++) {
                UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake(25+(width+15)*i, imgorighY, width, width)];
                img.userInteractionEnabled=YES;
                img.tag=i;
                NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",_urlString,[array objectAtIndex:i]]];
                //                [img sd_setImageWithURL:url placeholderImage:nil];
                [img sd_setImageWithURL:url];
                [_photosAr addObject:[MWPhoto photoWithURL:url]];
                [topView addSubview:img];
                img.userInteractionEnabled=YES;
                
                [img bk_whenTapped:^{
                    [self.audioPlayer stop];
                    self.audioPlayer.currentTime = 0;
                    
                    [_imageView stopAnimating];
                    
                    //预览图片
                    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
                    // Present
                    [self.navigationController pushViewController:browser animated:YES];
                    
                    browser.displayActionButton = NO;
                    browser.displayNavArrows = NO;
                    browser.displaySelectionButtons = NO;
                    browser.zoomPhotosToFill = YES;
                    browser.alwaysShowControls = NO;
                    browser.enableGrid = YES;
                    browser.startOnGrid = NO;
                    browser.autoPlayOnAppear = NO;
                    [browser setCurrentPhotoIndex:i];
                    
                    
                    UIView *backView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
                    [backView bk_whenTapped:^{
                        [self.navigationController popViewControllerAnimated:YES];
                    }];
                    
                    UIImage *icoBack = [UIImage imageNamed:@"Ico_nar_backWhite"];
                    UIImageView *imgBack = [[UIImageView alloc] initWithFrame:CGRectMake(0, (40-icoBack.size.height)/2, icoBack.size.width, icoBack.size.height)];
                    imgBack.image=icoBack;
                    imgBack.userInteractionEnabled=YES;
                    [backView addSubview:imgBack];
                    
                    UILabel *backTitle = [[UILabel alloc] init];
                    backTitle.frame=CGRectMake(CGRectGetMaxX(imgBack.frame) + 5, 0, 50 - imgBack.frame.size.width,40);
                    
                    [backTitle setText:@"返回"];
                    [backTitle setTextColor:[UIColor whiteColor]];
                    [backTitle setFont:F(14)];
                    [backView addSubview:backTitle];
                    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backView];
                    browser.navigationItem.leftBarButtonItem = leftBarButtonItem;
                    
                    
                    
                }];
            }
            
        }else if ([F_NSpace([dict objectForKey:@"image"]) isEqualToString:@""])
        {
            //只有视频
            imgHeight=width+10;
            
            UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake(25, imgorighY, width, width)];
            img.userInteractionEnabled=YES;
            [topView addSubview:img];
            
            NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",_urlString,[dict objectForKey:@"video"]]];
            
            UIImage *image = [UIImage imageNamed:@"Ico_home_play"];
            UIImageView* videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake((img.frame.size.width-image.size.width)/2, (img.frame.size.height-image.size.height)/2, image.size.width, image.size.height)];
            videoImageView.contentMode = UIViewContentModeScaleAspectFill;
            videoImageView.image=image;
            [img addSubview:videoImageView];
            img.image= [self cutMovieImageWith:url];
#pragma mark播放视频
            [_photosAr addObject:[MWPhoto videoWithURL:url]];
            
            [img bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                
                //预览图片
                MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
                // Present
                [self.navigationController pushViewController:browser animated:YES];
                
                browser.displayActionButton = NO;
                browser.displayNavArrows = NO;
                browser.displaySelectionButtons = NO;
                browser.zoomPhotosToFill = YES;
                browser.alwaysShowControls = NO;
                browser.enableGrid = YES;
                browser.startOnGrid = NO;
                browser.autoPlayOnAppear = NO;
                [browser setCurrentPhotoIndex:1];
                
                
                UIView *backView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
                [backView bk_whenTapped:^{
                    [self.navigationController popViewControllerAnimated:YES];
                }];
                
                UIImage *icoBack = [UIImage imageNamed:@"Ico_nar_backWhite"];
                UIImageView *imgBack = [[UIImageView alloc] initWithFrame:CGRectMake(0, (40-icoBack.size.height)/2, icoBack.size.width, icoBack.size.height)];
                imgBack.image=icoBack;
                imgBack.userInteractionEnabled=YES;
                [backView addSubview:imgBack];
                
                UILabel *backTitle = [[UILabel alloc] init];
                backTitle.frame=CGRectMake(CGRectGetMaxX(imgBack.frame) + 5, 0, 50 - imgBack.frame.size.width,40);
                
                [backTitle setText:@"返回"];
                [backTitle setTextColor:[UIColor whiteColor]];
                [backTitle setFont:F(14)];
                [backView addSubview:backTitle];
                UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backView];
                browser.navigationItem.leftBarButtonItem = leftBarButtonItem;
                
                
            }];
        }
        
    }else{
        //有视频和图片
        imgHeight=(width+10)*2;
        
        NSString *str =[dict objectForKey:@"image"];
        NSArray *array = [str componentsSeparatedByString:@","];
        for (int i=0; i<array.count+1; i++) {
            UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake(25+(width+15)*(i%3), imgorighY+(width+12)*(i/3), width, width)];
            img.userInteractionEnabled=YES;
            img.tag=i;
            [topView addSubview:img];
            if(i<array.count)
            {
                NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",_urlString,[array objectAtIndex:i]]];
                [img sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@""]];
                
                [_photosAr addObject:[MWPhoto photoWithURL:url]];
                img.userInteractionEnabled=YES;
            }
            if(i==array.count)
            {
                
                NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",_urlString,[dict objectForKey:@"video"]]];
                
                UIImage *image = [UIImage imageNamed:@"Ico_home_play"];
                UIImageView* videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake((img.frame.size.width-image.size.width)/2, (img.frame.size.height-image.size.height)/2, image.size.width, image.size.height)];
                videoImageView.contentMode = UIViewContentModeScaleAspectFill;
                videoImageView.image=image;
                [img addSubview:videoImageView];
                
                img.image= [self cutMovieImageWith:url];
#pragma mark播放视频
                [MWPhoto photoWithImage:img.image];
                
                [_photosAr addObject:[MWPhoto videoWithURL:url]];
            }
            [img bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                
                //预览图片
                MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
                // Present
                
                
                browser.displayActionButton = NO;
                browser.displayNavArrows = NO;
                browser.displaySelectionButtons = NO;
                browser.zoomPhotosToFill = YES;
                browser.alwaysShowControls = NO;
                browser.enableGrid = YES;
                browser.startOnGrid = NO;
                browser.autoPlayOnAppear = NO;
                [browser setCurrentPhotoIndex:i];
                
                [self.navigationController pushViewController:browser animated:YES];
                
                
                UIView *backView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
                [backView bk_whenTapped:^{
                    [self.navigationController popViewControllerAnimated:YES];
                }];
                
                UIImage *icoBack = [UIImage imageNamed:@"Ico_nar_backWhite"];
                UIImageView *imgBack = [[UIImageView alloc] initWithFrame:CGRectMake(0, (40-icoBack.size.height)/2, icoBack.size.width, icoBack.size.height)];
                imgBack.image=icoBack;
                imgBack.userInteractionEnabled=YES;
                [backView addSubview:imgBack];
                
                UILabel *backTitle = [[UILabel alloc] init];
                backTitle.frame=CGRectMake(CGRectGetMaxX(imgBack.frame) + 5, 0, 50 - imgBack.frame.size.width,40);
                
                [backTitle setText:@"返回"];
                [backTitle setTextColor:[UIColor whiteColor]];
                [backTitle setFont:F(14)];
                [backView addSubview:backTitle];
                UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backView];
                browser.navigationItem.leftBarButtonItem = leftBarButtonItem;
                
                
                
            }];
        }
    }
    
    topView.frame=CGRectMake(0, 10, WindowWidth, imgorighY+imgHeight+10);
    UIView*downView=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(topView.frame)+10, WindowWidth, 75)];
    downView.backgroundColor=[UIColor whiteColor];
    [_scrollView addSubview:downView];
    
    UILabel*lab=[[UILabel alloc]initWithFrame:CGRectMake(25, 15, 65, 15)];
    [downView addSubview:lab];
    lab.text =@"报修单号";
    lab.textColor =FontColor;
    lab.font =FF(14);
    
    UILabel*numLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab.frame), 15, WindowWidth-CGRectGetMaxX(lab.frame), 15)];
    [downView addSubview:numLab];
    if ([F_NSpace([dict objectForKey:@"order_number"]) isEqualToString:@""])
    {
        numLab.text =[dict objectForKey:@""];
        
    }else
    {
        numLab.text =[dict objectForKey:@"order_number"];
        
    }
    numLab.textColor =LightFontColor;
    numLab.font =FF(14);
    
#pragma mark     报修机构
    CGSize labelsize = [[dict objectForKey:@"instName"] sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-65, 900)];
  
    
    UILabel*lab4=[[UILabel alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(numLab.frame)+15, 65, 15)];
    [downView addSubview:lab4];
    lab4.text =@"报修机构";
    lab4.textColor =FontColor;
    lab4.font =FF(14);
    
    UILabel*addressLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab4.frame), CGRectGetMaxY(numLab.frame)+15, WindowWidth-CGRectGetMaxX(lab4.frame), labelsize.height)];
    [downView addSubview:addressLab];
    
    addressLab.textColor =MainColor;
    addressLab.font =FF(14);
    addressLab.numberOfLines=0;
    addressLab.text =[dict objectForKey:@"instName"];
    addressLab.userInteractionEnabled=YES;
    addressLab.text =[dict objectForKey:@"instName"];
    [addressLab bk_whenTapped:^{
        [self.audioPlayer stop];
        self.audioPlayer.currentTime = 0;
        [_imageView stopAnimating];
        ///报修机构
        NSMutableDictionary *dataDic=[[NSMutableDictionary alloc]init];
        [dataDic setObject:[dict objectForKey:@"latitude"] forKey:@"latitude"];
        [dataDic setObject:[dict objectForKey:@"longitude"]forKey:@"longitude"];
        [dataDic setObject:[dict objectForKey:@"instName"]forKey:@"addressName"];
        LocationViewController *locationVC=[[LocationViewController alloc]init];
        locationVC.dataDic=dataDic;
        [self pushController:locationVC];
        
    
    }];
    downView.frame=CGRectMake(0, CGRectGetMaxY(topView.frame)+10, WindowWidth, CGRectGetMaxY(addressLab.frame)+15);
    CGFloat height=CGRectGetMaxY(downView.frame);
    
    if((height)>(WindowHeight-64))
    {
        _scrollView.scrollEnabled=YES;
        
        if (WindowHeight==480) {
            _scrollView.contentSize =CGSizeMake(0, WindowHeight+300);
            
        }else
        {
            _scrollView.contentSize =CGSizeMake(0, WindowHeight+200);
        }
    }else
    {
        _scrollView.scrollEnabled=NO;
    }
    
    
}
#pragma mark 获取视频首帧图片
-(UIImage*)cutMovieImageWith:(NSURL*)urlString{
    //创建URL
    NSURL *url=urlString;
    //根据url创建AVURLAsset
    AVURLAsset *urlAsset=[AVURLAsset assetWithURL:url];
    //根据AVURLAsset创建AVAssetImageGenerator
    AVAssetImageGenerator *imageGenerator=[AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
    imageGenerator.appliesPreferredTrackTransform = YES;
    /*截图
     * requestTime:缩略图创建时间
     * actualTime:缩略图实际生成的时间
     */
    NSError *error=nil;
    CMTime time=CMTimeMakeWithSeconds(1, 1);//CMTime是表示电影时间信息的结构体，第一个参数表示是视频第几秒，第二个参数表示每秒帧数.(如果要活的某一秒的第几帧可以使用CMTimeMake方法)
    CMTime actualTime;
    CGImageRef cgImage= [imageGenerator copyCGImageAtTime:time actualTime:&actualTime error:&error];
    if(error){
        //        DSLog(@"截取视频缩略图时发生错误，错误信息：%@",error.localizedDescription);
        return nil;
    }
    CMTimeShow(actualTime);
    UIImage *cutImage=[UIImage imageWithCGImage:cgImage];//转化为UIImage
    return cutImage;
}
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    
    return _photosAr.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _photosAr.count) {
        return [_photosAr objectAtIndex:index];
    }
    return nil;
}
//自定义标题

- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser

      titleForPhotoAtIndex:(NSUInteger)index {
    return @"查看图片";
    
}

@end
